package cn.gson.springboot.model.service.privilegeservice;

import cn.gson.springboot.model.mapper.privilegemapper.DeptMapper;
import cn.gson.springboot.model.pjos.Emp;
import cn.gson.springboot.model.vo.privilegevo.DeptPositionVo;
import cn.gson.springboot.model.vo.privilegevo.DeptVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 用于数据控制
 */
@Service
@Transactional
public class DataControlService {
    @Autowired
    DeptMapper deptMapper;

    /** 查询用户是否是一级角色*/
    public DeptPositionVo deptPost(Integer empId){
        return deptMapper.deptPost(empId);
    }

    /*查询自己所在的部门*/
    public DeptVo oneSelfDept(Integer deptId){
        return deptMapper.oneSelfDept(deptId);
    }

    /**递归查询拥有指定模块的子部门*/
    public List<DeptVo> childrenDept(Integer psetId, Integer fatherDeptId){
        List<DeptVo> list = new ArrayList<>();
        list.add(oneSelfDept(fatherDeptId));
        //子部门
        List<DeptVo> deptVos= deptMapper.childrenDept(psetId,fatherDeptId);
        for(int i=0;i<deptVos.size();i++){
              list.add(deptVos.get(i));
        }
        return  list;
    }



    /**
     * 查询部门下的员工
     * */
    public List<Emp> selectEmp(Integer deptId){
         return deptMapper.selectEmp(deptId);
    }

}
